package com.gitee.wsl.css.selector.builder

import com.gitee.wsl.css.selector.CompoundSelector
import com.gitee.wsl.css.selector.PseudoSelector
import com.gitee.wsl.css.selector.Selector
import com.gitee.wsl.transform.escape.sample.escapeXml


val Selector.active get() = PseudoSelector(this, ":active")
val Selector.after get() = PseudoSelector(this, ":after")
val Selector.before get() = PseudoSelector(this, ":before")
val Selector.checked get() = PseudoSelector(this, ":checked")
val Selector.disabled get() = PseudoSelector(this, ":disabled")
val Selector.empty get() = PseudoSelector(this, ":empty")
val Selector.enabled get() = PseudoSelector(this, ":enabled")
val Selector.firstChild get() = PseudoSelector(this, ":first-child")
val Selector.firstLetter get() = PseudoSelector(this, ":first-letter")
val Selector.firstLine get() = PseudoSelector(this, ":first-line")
val Selector.firstOfType get() = PseudoSelector(this, ":first-of-type")
val Selector.focus get() = PseudoSelector(this, ":focus")
val Selector.hover get() = PseudoSelector(this, ":hover")
val Selector.inRange get() = PseudoSelector(this, ":in-range")
val Selector.invalid get() = PseudoSelector(this, ":invalid")
val Selector.lastChild get() = PseudoSelector(this, ":last-child")
val Selector.lastOfType get() = PseudoSelector(this, ":last-of-type")
val Selector.onlyChild get() = PseudoSelector(this, ":only-child")
val Selector.onlyOfType get() = PseudoSelector(this, ":only-of-type")
val Selector.optional get() = PseudoSelector(this, ":optional")
val Selector.outOfRange get() = PseudoSelector(this, ":out-of-range")
val Selector.readOnly get() = PseudoSelector(this, ":read-only")
val Selector.readWrite get() = PseudoSelector(this, ":read-write")
val Selector.required get() = PseudoSelector(this, ":required")
val Selector.root get() = PseudoSelector(this, ":root")
val Selector.selection get() = PseudoSelector(this, ":selection")
val Selector.target get() = PseudoSelector(this, ":target")
val Selector.unvisited get() = PseudoSelector(this, ":link")
val Selector.valid get() = PseudoSelector(this, ":valid")
val Selector.visited get() = PseudoSelector(this, ":visited")

//
// TRAVERSING
//
val Selector.children get() = PseudoSelector(this, " ")
val Selector.child get() = PseudoSelector(this, ">")
val Selector.next get() = PseudoSelector(this, "+")
val Selector.nextAll get() = PseudoSelector(this, "~")

operator fun Selector.div(obj: Selector) = child.and(obj)
operator fun Selector.rem(obj: Selector) = next.and(obj)
operator fun Selector.minus(obj: Selector) = nextAll.and(obj)
operator fun Selector.rangeTo(obj: Selector) = children.and(obj)

infix fun Selector.and(obj: Selector) = CompoundSelector(this,obj)

fun Selector.attr(attrName: Any) = PseudoSelector(this,"[$attrName]")

fun Selector.attr(
    attrName: Any,
    attrValue: Any
) = PseudoSelector(this,"[$attrName=${attrValue.toString().escapeXml}]")
